package com.tanhua.app.controller;

import com.tanhua.app.controllerservice.TanHuaService;
import com.tanhua.domain.vo.UserHolder;
import com.tanhua.domain.vo.TodayBest;
import com.tanhua.domain.vo.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanHuaController {

    @Autowired
    private TanHuaService tanHuaService;

    @GetMapping(name = "今日佳人查询", value = "/todayBest")
    public ResponseEntity todayBest() {

        return tanHuaService.todayBest();
    }

    @GetMapping(name = "佳人信息的分页展示", value = "/recommendation")
    public ResponseEntity recommendation(Integer page, Integer pagesize) {

        return tanHuaService.recommendation(page, pagesize);
    }


    @GetMapping(name = "佳人个人详情展示", value = "/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Integer jrid) {
        return tanHuaService.personalInfo(jrid);
    }


    @GetMapping(name = "查询陌生人问题", value = "/strangerQuestions")
    public ResponseEntity strangerQuestions(Integer userId) {
        return tanHuaService.strangerQuestions(userId);
    }


    @PostMapping(name = "发送验证消息", value = "/strangerQuestions")
    public ResponseEntity toStrangerQuestions(@RequestBody Map map) {

        Integer userId = (Integer) map.get("userId"); //115
        String info = (String) map.get("reply"); //是的
        System.out.println(userId);
        System.out.println(info);
        return tanHuaService.toStrangerQuestions(userId, info);
    }

//    @GetMapping(name = "桃花传音-喜欢", value = "/{id}/love")
//    public ResponseEntity<String> like(@PathVariable("id") Long otherUserId) {
//        return tanHuaService.like(UserHolder.getUser().getId(), otherUserId);
//    }

    @GetMapping("cards")
    public ResponseEntity<List<TodayBest>> queryCardsList() {
        try {
            List<TodayBest> list = this.tanHuaService.queryCardsList();
            return ResponseEntity.ok(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    @GetMapping("{id}/love")
    public ResponseEntity<Void> loveUser(@PathVariable("id") Long UserId) {

        this.tanHuaService.loveUser(UserId);
        return ResponseEntity.ok(null);
    }


    @GetMapping("{id}/unlove")
    public ResponseEntity<Void> notLoveUser(@PathVariable("id") Long UserId) {
        this.tanHuaService.DisloveUser(UserId);
        return ResponseEntity.ok(null);
    }

//    @GetMapping(name = "桃花传音-不喜欢", value = "/{id}/unlove")
//    public ResponseEntity<String> dislike(@PathVariable("id") Long otherUserId) {
//        return tanHuaService.dislike(UserHolder.getUser().getId(), otherUserId);
//    }
}
